home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi 2.0 - Programmer's Utilities Power Pack
/
Delphi 2.0 Programmer's Utilities Power Pack.iso
/
a_to_d
/
dbfilt15
/
fltdemo1.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-09-15
|
5KB
|
145 lines
unit Fltdemo1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, DBTables, DB, Grids, DBGrids,
StdCtrls, Buttons, DBFiltUZ, VisApp;
type
TForm1 = class(TForm)
Database1: TDatabase;
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
UZFilter1: TUZFilter;
BitBtn2: TBitBtn;
Table2: TTable;
GroupBox1: TGroupBox;
CheckBox1: TCheckBox;
DataSource2: TDataSource;
DBGrid2: TDBGrid;
UZFilter2: TUZFilter;
GroupBox2: TGroupBox;
CheckBox2: TCheckBox;
Table2OrderNo: TFloatField;
Table2CustNo: TFloatField;
Table2ItemsTotal: TCurrencyField;
Table2SaleDate: TDateTimeField;
Table2ShipDate: TDateTimeField;
function UZFilter1FilterRecord(Sender: TObject; RecNo: Longint;
DataSet: TDataset): Boolean;
function UZFilter2FilterRecord(Sender: TObject; RecNo: Longint;
DataSet: TDataset): Boolean;
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure CheckBoxSetDisplay;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{---------------------------------------------------------------------------
* Here it is, the callback function used to filter the TTable/TDataSet
*
* NOTE: though it seems trivial, here is done something, which wouldn't
* be possible with DELPHI renages/filtering, because the
* FILTER-FIELD is NOT THE INDEXED FIILD
*
* ALL YOU HAVE TO CODE IS THIS !!!
*
*---------------------------------------------------------------------------}
function TForm1.UZFilter1FilterRecord(Sender: TObject; RecNo: Longint;
DataSet: TDataset): Boolean;
begin
Result := (DataSet.FieldByName('CustNo').AsInteger > 1500) and
(DataSet.FieldByName('CustNo').AsInteger < 2200);
end;
{---------------------------------------------------------------------------
* this is the filter callback for the detail table ORDERS
*
* NOTE: -> the filters are INDEPENDANT from each other
* -> if using a mastersourced (linked) DataSource, the DATAIL-checks
* go HEREIN !!
*
* ALL YOU HAVE TO CODE IS THIS !!!
*
*---------------------------------------------------------------------------}
function TForm1.UZFilter2FilterRecord(Sender: TObject; RecNo: Longint;
DataSet: TDataset): Boolean;
begin
Result := (DataSet.FieldByName('ItemsTotal').AsInteger > 5000);
end;
{---------------------------------------------------------------------------
* all the other stuff is just to get a proper outfit for the demo
*---------------------------------------------------------------------------}
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
UZFilter1.Active := not(UZFilter1.Active);{ just switch the filter on/off }
CheckBoxSetDisplay; { update diplay for CheckBoxes }
{---------------------------------------------------------------------------
* you might try these, but before doing so, 'please examine the DBFILTUZ.INT
* CAREFULLY to check specially the security functions
*---------------------------------------------------------------------------}
(* DataSource1.DataSet.Active := { switch the dataset active-mode }
not(DataSource1.DataSet.Active); *)
(* Table3.Active := true; { switch to another table }
DataSource1.DataSet := Table3; { NOTE: must add another TTable first !! }
*)
(* UZFilter1.DataSource := nil; { kill filter's datasource }
*)
end;
procedure TForm1.CheckBox2Click(Sender: TObject);
begin
UZFilter2.Active := not(UZFilter2.Active);{ just switch the filter on/off }
CheckBoxSetDisplay; { update diplay for CheckBoxes }
end;
procedure TForm1.CheckBoxSetDisplay;
begin
with CheckBox1 do begin { all on CheckBox1 }
If UZFilter1.Active then begin { is the filter active ? }
Caption := '1500 > CustNo < 2200';
Font.Color := clLime;
Checked := true;
end else begin { ! no inactive }
Caption := 'inactive';
Font.Color := clRed;
Checked := false;
end; { ? UZFilter2 active }
end; { with CheckBox1 }
with CheckBox2 do begin { all on CheckBox1 }
If UZFilter2.Active then begin { is the filter active ? }
Caption := 'ItemsTotal > 5000';
Font.Color := clLime;
Checked := true;
end else begin { ! no inactive }
Caption := 'inactive';
Font.Color := clRed;
Checked := false;
end; { ? UZFilter1 active }
end; { with CheckBox1 }
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
CheckBoxSetDisplay; { update display for CheckBoxes }
end;
end.